package com.DesignMode.Singleton;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/10/09/16:51
 * @Description: private static 以及null才创建,保证单例
 * @Target: 懒汉式单例
 */
public class LazySingleton {

    private LazySingleton() {
//        System.out.println(Thread.currentThread().getName()+"OK");
    }


    private static LazySingleton lazySingleton;


    public static LazySingleton getInstance(){
            if(lazySingleton==null){
                lazySingleton = new LazySingleton();
            }
            return lazySingleton;
    }

    // 多线程并发下就不安全了
/*

    // test
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                LazySingleton.getInstance();
            }).start();
        }
    }

*/

}
